All Questions
21 questions
0votes
1answer
107views
Printing Permutations
Following is a leetcode problem: Given an array nums of distinct integers, return all the possible permutations. You can return all the possible permutations. You can return the answer in any order. ...
2votes
1answer
1kviews
Drawing dragon curves using Turtle graphics
This is exercise 3.2.23. from the book Computer Science An Interdisciplinary Approach by Sedgewick & Wayne: Write a recursive Turtle client that draws dragon fractal. The following is the data-...
5votes
1answer
261views
Drawing a Thue-Morse pattern recursively
This is web exercise 3.1.63. from the book Computer Science An Interdisciplinary Approach by Sedgewick & Wayne: Write a program that reads in a command line input N and plots the N-by-N Thue-...
2votes
2answers
252views
Write a recursive function that takes a positive integer n and plots an N-by-N Hadamard pattern where N = 2^n
This is web exercise 2.3.20. from the book Computer Science An Interdisciplinary Approach by Sedgewick & Wayne: Write a recursive program that takes a command-line argument n and plots an N-by-N ...
4votes
1answer
112views
Printing Gray code through modifying Samuel Beckett's stage instructions
This is exercise 2.3.24. from the book Computer Science An Interdisciplinary Approach by Sedgewick & Wayne: Modify Beckett to print the Gray code. Beckett refers to the following program within ...
4votes
1answer
303views
Minimax based Tic Tac Toe
I am attempting to make an unbeatable Tic Tac Toe game using a simplified minimax algorithm. The code looks like this: ...
5votes
2answers
493views
How to optimize Karatsuba algorithm (using arraylist and java)
I was using Karatsuba algorithm to multiply two polynomials and return the coefficients and I am using java, we are asked to use arraylists here, however, my code is too complicated and it takes much ...
3votes
3answers
531views
Sudoku Solver questions on style and algorithm
I am working towards a CSC degree right now and wanted to try and practice writing good code that could be easily maintained and read in industry. I wrote the following program in Java that takes a ...
3votes
1answer
3kviews
Java n-ary Tree class with custom made methods and nested Node class
I'm a beginner and I wrote this (working) code for n-ary tree. The specifics: Each node is to be built with an integer value. Each node has a variable number of children. The nodes should have an ...
1vote
1answer
329views
Rearrange an array in place such that the first and last halves are interleaved
Given an array of n elements in the following format { a1, a2, a3, a4, ….., an/2, b1, b2, b3, b4, …., bn/2 }. The task is shuffle the array to {a1, b1, a2, b2, a3, b3, ……, an/2, bn/2 } without ...
0votes
2answers
958views
Number of Paths (BackTracking) in Java
Illustration You're testing a new driverless car that is located at the Southwest (bottom-left) corner of an n×n grid. The car is supposed to get to the opposite, Northeast (top-right), corner ...
3votes
2answers
2kviews
Recursive Contains Method
The method below recursively checks if a string contains another string. Example: contains(hello, lo, 0) should return true, ...
5votes
1answer
6kviews
Replacing characters in a Java string using iteration and recursion
I am new to the whole Data Structures thing and I want to get better at writing efficient code. So, I have been practicing some problem sets. The questions is - Replace characters in a string using ...
-7votes
1answer
1kviews
Counting number of steps while finding right path [closed]
I am writing a code which would return the path in a maze using recursion, but now with the path I also want the number of steps. How do count number of steps in this program? or number of times ...
5votes
3answers
5kviews
Using recursion to count substrings (with exceptions to the rule) in Java
I am going through the CodingBat exercises for Java. Here is the one I have just finished: Given a string, compute recursively the number of times lowercase hi ...